package com.itheima.pinda.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pinda.DTO.angency.FleetDto;
import com.itheima.pinda.DTO.transportline.TransportLineTypeDto;
import com.itheima.pinda.common.utils.PageResponse;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdFleetService;
import com.itheima.pinda.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "车队管理")
@RestController
@RequestMapping(value = "/base/fleet")
public class PdFleetController {

    @Autowired
    private PdFleetService fleetService;

    @ApiOperation(value = "新增车队")
    @PostMapping(value = "/insert")
    public FleetDto insert(FleetDto fleetDto){
        return fleetService.insert(fleetDto);
    }

    @ApiOperation(value = "更新车队")
    @PostMapping(value = "/update")
    public FleetDto update(FleetDto fleetDto) {
        return fleetService.insert(fleetDto);
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/id")
    public FleetDto selectById(@RequestParam("id") String id){

        return fleetService.selectById(id);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/selectByPage")
    public PageResponse selectByPage(@RequestParam(name = "page") Integer pageNum,
                                     @RequestParam(name = "pageSize") Integer pageSize,
                                     @RequestParam(name = "name", required = false) String name,
                                     @RequestParam(name = "fleetNumber", required = false) String fleetNumber,
                                     @RequestParam(name = "manager", required = false) String manager){
        IPage page = fleetService.selectByPage(pageNum, pageSize, name, fleetNumber, manager);

        return ResultUtils.pageResult(pageNum,pageSize,page);
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping(value = "/ids")
    public Result deleteById(@RequestParam("ids") List<String> ids){

        fleetService.deleteById(ids);
        return Result.ok("删除成功！");
    }
}
